package metamodels;

import java.util.ArrayList;
import java.util.List;

import parser.generic.Node;

public class Classifiers extends Node{

	private List<Classifier> classifiers;
	
	public List<Classifier> getClassifiers() {
		return classifiers;
	}

	public Classifiers() {
		this.classifiers = new ArrayList<Classifier>();
	}

	public void addClassifier(Classifier classifier)
	{
		classifiers.add(classifier);
	}
	
	@Override
	public String toString() {
		String out = "";
		
		for (Classifier c : classifiers)
		{
			out += c + "\n";
		}
		
		return out;
	}
	
	public String getInheritanceRules()
	{
		String out = "";
		List<Identifier> temp;
		for(int i = 0; i < classifiers.size(); i++)
		{
			Classifier cls = classifiers.get(i);
			if (cls instanceof Class)
			{
				temp = new ArrayList<Identifier>();
				for(int j = 0; j < classifiers.size(); j++)
				{
					Classifier cls_child = classifiers.get(j);
					if (cls_child instanceof Class)
					{
//						System.out.println("Check if: " + cls_child.getName() + " is parent of " + cls.getName());
						if (((Class)cls).isParentOf((Class)cls_child))
						{
							temp.add(cls_child.getIdentifier());
						}
					}
				}
				if (temp.size() > 0)
				{
					for(Identifier id : temp)
						out += "rule children(" + ((Class)cls).getName() + ") => .Bag BagItem(" + id.toString() + ") [:structural:]\n";
				}
				else out += "rule children(" + ((Class)cls).getName() + ") => .Bag  [:structural:]\n";
			}
		}
		return out;
	}

	public String getAttributeDeclRules() {
		
		String out = "";
		
		for(Classifier cls : classifiers)
			if (cls instanceof Class)
			{
				out += ((Class)cls).getAttributeDeclRules() + "\n\n";
			}
		
		return out;
	}

	public String getEnumRules() {

		String out = "";
		
		for(Classifier cls : classifiers)
			if (cls instanceof Enumeration)
			{
				out += ((Enumeration)cls).getEnumRules() + "\n\n";
			}
		
		return out;
	}

	public String getEnumValuesRule() {
String out = "";
		
		for(Classifier cls : classifiers)
			if (cls instanceof Enumeration)
			{
				out += ((Enumeration)cls).getEnumValuesRule() + "\n\n";
			}
		
		return out;
	}
}
